/*
	Created: Jonathan Turner
		On : 10/18/2013
Description: Gets document type info from ID.
	Updates:
*/
ALTER PROCEDURE daycare.GetEmployeeDocuments
  @EmployeeId INT
, @IncludeExpiredDocuments BIT
, @DocumentTypeId INT = NULL
AS 
  IF @IncludeExpiredDocuments = 0 
    BEGIN
      SELECT  doc.DocumentId
            , doc.DocumentName
            , doc.FileName
            , doc.DocumentTypeId
            , doc.ExpirationDate
      FROM    daycare.Documents AS doc
      INNER JOIN daycare.EmployeeDocuments AS ed ON doc.DocumentId = ed.DocumentId
      WHERE   ed.EmployeeId = @EmployeeId
              AND (
                   doc.DocumentTypeId = @DocumentTypeId
                   OR @DocumentTypeId IS NULL
                  )
              AND CONVERT(DATETIME,doc.ExpirationDate) >= GETDATE() 
    END
  ELSE 
    BEGIN
      SELECT  doc.DocumentId
            , doc.DocumentName
            , doc.FileName
            , doc.DocumentTypeId
            , doc.ExpirationDate
      FROM    daycare.Documents AS doc
      INNER JOIN daycare.EmployeeDocuments AS ed ON doc.DocumentId = ed.DocumentId
      WHERE   ed.EmployeeId = @EmployeeId
              AND (
                   doc.DocumentTypeId = @DocumentTypeId
                   OR @DocumentTypeId IS NULL
                  )
    END
GO